<template>
    <div class="mainBody">
      <div>
        <el-form :inline="true" :model="formInline" class="demo-form-inline" id="searchMap">
          <el-form-item label="题型名字">
            <el-input v-model="formInline.questionTypeName" placeholder="题型名字"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="getASpecialPage">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="info" @click="initialization">初始化/刷新</el-button>
          </el-form-item>
          <el-form-item>
            <router-link :to="{path:'/addQuestionTypeInformation'}">
              <el-button type="success">新增</el-button>
            </router-link>
          </el-form-item>
        </el-form>
      </div>

      <div>
        <el-table
          :data="questionTypeData"
          ref="multipleTable"
          border
          tooltip-effect="dark"
          style="margin: 0 auto;background: oldlace;"
          @select="handleSelectionChange">
          <el-table-column type="selection" width="40">
          </el-table-column>
          <el-table-column
            label="id"
            width="60">
            <template slot-scope="questionTypeData">{{questionTypeData.row.id}}</template>
          </el-table-column>
          <el-table-column
            label="题型名字"
            width="420">
            <template slot-scope="questionTypeData">{{questionTypeData.row.questionTypeName}}</template>
          </el-table-column>
          <el-table-column
          label="操作">
          <template slot-scope="questionTypeData">
            <el-button size="mini" type="danger"@click="handleDelete(questionTypeData.row.id)">删除</el-button>
            <router-link :to="{path:'/showQuestionType',query:{id:questionTypeData.row.id}}">
              <el-button size="mini" type="primary">查看详情</el-button>
            </router-link>
          </template>
        </el-table-column>
        </el-table>
        <el-pagination
          style="margin-top:15px;"
          background
          layout="prev, pager, next"
          :current-page.sync="pagination.page"
          :page-size.sync="pagination.size"
          :total="pagination.count"
          @current-change="handleCurrentChange">
        </el-pagination>
      </div>
    </div>
</template>

<script>
  import qs from 'qs'
    export default {
        name: "QuestionType",
        data(){
          return{
            addDialog:false,
            editDialog:false,
            questionTypeData:null,
            queryType:1,
            pagination: {
              page: 1,
              size: 8,
              count: 0,
            },
            questionTypeItem:{
              id:'',
              questionTypeName:''
            },
            formInline:{
              questionTypeName:''
            }
          }
        },
      created(){
          this.getAPage();
      },
      methods:{
        initialization(){
          this.queryType=1;
          this.formInline.questionTypeName='';
          this.pagination.page=1;
          this.getAPage();
        },
        getAPage(){
          if(this.queryType!=1){
            this.queryType=1;
            this.pagination.page=1;
          }
          this.$axios.post('/questionType/getAPage',qs.stringify(this.pagination))
            .then(res=>{
              this.questionTypeData = res.data.result;
              this.pagination.count = res.data.count;
            })
            .catch(err=>{
              this.$message({
                message:'获取数据错误',
                type: 'error',
                duration: 3000
              })
            })
        },
        getASpecialPage(){
          if(this.queryType!=2){
            this.queryType=2;
            this.pagination.page=1;
          }
          this.$axios.post('/questionType/getASpecialPage',qs.stringify({
            questionTypeName: this.formInline.questionTypeName,
            page:this.pagination.page,
            size:this.pagination.size
          }))
            .then(res=>{
              console.log(res.data.result);
              this.questionTypeData = res.data.result;
              this.pagination.count = res.data.count;
            })
            .catch(err=>{
              this.$message({
                message:'获取数据错误',
                type: 'error',
                duration: 3000
              })
            })
        },
        handleCurrentChange(page) {
          this.pagination.page = page;
          if(this.queryType==1)
            this.getAPage();
          if(this.queryType==2)
            this.getASpecialPage()
        },
        handleDelete(id){
          this.$axios.post('/questionType/deleteQuestionType',qs.stringify({
            questionTypeId:id
          }))
            .then(res=>{
              this.$message({
                message:res.data.msg,
                duration: 3000
              })
              this.initialization()
            })
            .catch(err=>{
              this.$message({
                message:'获取数据错误',
                type: 'error',
                duration: 3000
              })
            })
        },
      }
    }
</script>

<style scoped>
  .mainBody{
    width: 100%;
    background: #ffffff;

  }
  #searchMap{
    width: 800px;
    padding-top: 15px;
    padding-left: 40px;
  }
</style>
